#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@NAME          : basedata.py
@TIME          : 2025/02/23 19:38:15
@AUTHOR        : chenlip
@VERSION       : 0.0.1
@DESCRIPTION   : 基础数据模型, 读取基础数据basedata.json
'''
# --------------------------引用--------------------------
import os, sys, json
# --------------------------引用--------------------------

class BaseData(object):
    '''
        描述
    '''
    ACTION_TYPE = [
            "登录",
            "登出",
            "修改密码",
            "修改资料",
            "购买积分",
            "兑换积分",
            "送分",
            "审核主贴",
            "审核回复",
            "关注用户",
            "关注主题",
            "关注版块",
            "点赞主贴",
            "点赞回复",
            "点赞资源",
            "收藏主贴",
            "收藏资源",
            "回复主贴",
            "回复回复",
            "添加主贴",
            "编辑主贴",
            "删除主贴",
            "删除回复",
            "删除资源",
            "上传资源",
            "下载资源",
            "分享主贴",
            "分享资源",
            "举报主贴",
            "举报回复",
            "举报资源",
            "其他"
        ]
    
    TARGET_TYPE = ["用户","主贴","版块","回复","资源","标签"]

    def __init__(self):
        '''
            初始化
        '''
        self.data = None
        with open("basedata.json", "r") as f:
            self.data = json.load(f)

    def get_index(self, t_f:list, title: str = None) -> int:
        '''
            根据枚举值获取枚举序号
            :Args:
                - t_f: 表名和字段名，例如：["user", "static"]
                - title: 标题
            :Return:
                - 枚举序号: int, 如果未找到则返回 -1
        '''
        if title is None:
            return -1
        
        _t_lst = []
        
        if t_f[0] in self.data.keys() and t_f[1] in self.data[t_f[0]].keys():
            _t_lst = self.data[t_f[0]][t_f[1]]
        
        if t_f[1] == "action_type":
            _t_lst = self.ACTION_TYPE
        elif t_f[1] == "target_type":
            _t_lst = self.TARGET_TYPE

        for i, v in enumerate(_t_lst):
            if v == title:
                return i
        
        return -1

    def get_value(self, t_f: list, index: int) -> str:
        '''
            根据枚举序号获取枚举值
            :Args:
                - t_f: 表名和字段名，例如：["user", "static"]
                - index: 枚举序号
            :Return:
                - 枚举值: str, 如果未找到则返回 "None"
        '''
        _t_lst = []

        if t_f[0] in self.data.keys() and t_f[1] in self.data[t_f[0]].keys():
            _t_lst = self.data[t_f[0]][t_f[1]]
            if 0 <= index < len(_t_lst):
                return str(_t_lst[index])
        
        return "None"

    def get_all_values(self, t_f: list):
        '''
            获取所有枚举值
            :Args:
                - t_f: 表名和字段名，例如：["user", "static"]
            :Return:
                - 枚举值列表: list
        '''
        values = []
        if t_f[0] in self.data.keys() and t_f[1] in self.data[t_f[0]].keys():
            values = self.data[t_f[0]][t_f[1]]
        
        return values

    # func
